﻿using System;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;

using LTJ.Entity;
using LTJ.Common;
using LTJ.Config;
using LTJ.FrameWork;

namespace LTJ.WebPage.SystemManage.route
{
    /// <summary>
    /// 授权航线查看
    /// </summary>
    public partial class fclroutecollection : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDataGrid();
            }
        }

        protected void BindDataGrid()
        {
            string strWhere = "";

            if (ViewState["condition"] == null || ViewState["condition"].ToString() == "")
            {
                strWhere += "";
            }
            else
            {
                strWhere += ViewState["condition"].ToString();
            }

            DataGrid1.VirtualItemCount = Routes.GetRoutesCount(strWhere);
            DataGrid1.DataSource = Routes.GetRoutesByPage(DataGrid1.CurrentPageIndex + 1, DataGrid1.PageSize, strWhere, "", "");
            DataGrid1.DataBind();
        }

        protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
        {
            DataGrid1.CurrentPageIndex = e.NewPageIndex;
            BindDataGrid();
        }

        protected void GoToPagerButton_Click(object sender, EventArgs e)
        {
            BindDataGrid();
        }

        /// <summary>
        /// 搜索点击
        /// </summary>
        protected void check_Click(object sender, EventArgs e)
        {
            string search_routeline = SASRequest.GetString("ajaxroutelinedatalist_value");
            string search_boatname = SASRequest.GetString("ajaxcarrierlist_value");
            int search_company = SASRequest.GetInt("ajaxcorpdatalist_value", 0);
            string search_sql = "1=1";
            if (search_routeline != "") search_sql += " and tcode = '" + search_routeline + "'";
            if (search_boatname != "") search_sql += " and bcode = '" + search_boatname + "'";
            if (search_company > 0) search_sql += " and cid = " + search_company;
            ViewState["condition"] = search_sql;
            DataGrid1.CurrentPageIndex = 0;
            BindDataGrid();
        }

        /// <summary>
        /// 重新绑定
        /// </summary>
        protected void reclick_Click(object sender, EventArgs e)
        {
            BindDataGrid();
        }

        /// <summary>
        /// 删除规则
        /// </summary>
        protected void del_Click(object sender, EventArgs e)
        {
            if (SASRequest.GetString("cid") != "")
            {
                Routes.DelRoutes(SASRequest.GetString("cid"));
                BindDataGrid();
            }
        }

        #region Web 窗体设计器生成的代码

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            DataGrid1.PageIndexChanged += new DataGridPageChangedEventHandler(DataGrid1_PageIndexChanged);
            DataGrid1.GoToPagerButton.Click += new EventHandler(GoToPagerButton_Click);
            DataGrid1.AllowCustomPaging = true;
            DataGrid1.TableHeaderName = "航线授权列表";
            DataGrid1.Attributes.Add("borderStyle", "0");
            DataGrid1.DataKeyField = "id";
            DataGrid1.ColumnSpan = 12;
            DataGrid1.SaveDSViewState = true;

            check.Click += new EventHandler(check_Click);
            reclick.ServerClick += new EventHandler(reclick_Click);
            del.Click += new EventHandler(del_Click);
        }

        #endregion
    }
}